<?php
namespace app\tadmin\controller\category;
use app\tadmin\controller\Controller as BaseController;
use think\Db;
/**
 * 体育专题
 * Class Index
 * @package app\tadmin\controller
 */
class Website extends BaseController{

    public function index(){
        $title = input('get.title' , '');
        if(!empty($tag_name)){
            $list = Db::name('website')->where('title' , $title)->order('id desc')->paginate(15);    
        }else{
            $list = Db::name('website')->order('id desc')->paginate(15);
        }
        //print_r(ArticleDocModel::getLastSql());
        return $this->fetch('index' , compact('list'));
    }

    public function add(){
        if (!$this->request->isAjax()) {
            return $this->fetch('add');
        }
        $doc = input('doc/a');
        $doc['update_time'] = date('Y-m-d H:i:s');
        $res = Db::name('website')->insertGetId($doc);
        if($res){
            return $this->renderSuccess('添加成功',url('category.website/index'));
        }else{
            return $this->renderError('添加失败');
        }
    }

    public function edit(){
        if (!$this->request->isAjax()) {
            $id = input('id');
            $info = Db::name('website')->where('id' , $id)->find();
            //print_r($info);
            return $this->fetch('edit', compact('info'));
        }
        $doc = input('doc/a');
        $doc['update_time'] = date('Y-m-d H:i:s');
        $id = $doc['id'];
        unset($doc['id']);
        $res = Db::name('website')->where('id' , $id)->update($doc);
        if($res){
            return $this->renderSuccess('编辑成功',url('category.website/index'));
        }else{
            return $this->renderError('编辑失败');
        }
    }

    public function delete($id){
        $res = Db::name('website')->where('id' , $id)->delete();
        if (!$res) {
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess('删除成功');
    }
}